﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// 委托是一种类型

namespace 委托01
{
    /// <summary>
    /// 委托，可以赋值一个方法的引用
    /// 它的返回值和方法必须要与被委托的方法一致，否则不能匹配，也就不能实现委托
    /// </summary>
    public delegate void SayHello();

    class Program
    {
        static void Main(string[] args)
        {
            //Meet("China");
            //Meet("Japan");

            // 委托的本质就是把方法作为参数进行传递，通过委托去执行方法
            Meet(SayHelloInAmerica);
            SayHello sh = new SayHello(SayHelloInHanGuo);
            Meet(sh);
        }

        public static void SayHelloInChina()
        {
            Console.WriteLine("吃了吗");
        }
        public static void SayHelloInAmerica()
        {
            Console.WriteLine("what's the weather");
        }
        public static void SayHelloInJapan()
        {
            Console.WriteLine("空你系哇");
        }
        public static void SayHelloInHanGuo()
        {
            Console.WriteLine("...思密达");
        }
        public static void AnyCountry()
        {
            Console.WriteLine(".....");
        }


        public static void Meet(SayHello say)
        {
            say();  // 执行委托
        }

        public static void Meet(string s)
        {
            if (s == "China")
            {
                SayHelloInChina();
            }
            if (s == "America")
            {
                SayHelloInAmerica();
            }
            if (s == "Japan")
            {
                SayHelloInJapan();
            }
            if (s == "HanGuo")
            {
                SayHelloInHanGuo();
            }
        }


    }
}
